//
//  YZDBManager.h
//  CocoaAsyncSocketClient
//
//  Created by lixiaoyi on 2018/7/4.
//  Copyright © 2018年 lixiaoyi. All rights reserved.
//

/*
 * 数据库工具类
 */

#import <Foundation/Foundation.h>

// 消息记录表
#define kChatRecordTable        @"ChatRecordTable"
// 消息列表表
#define kChatMessageListTable   @"ChatMessageListTable"
// 新朋友表
#define kNewFriendTable         @"NewFriendTable"

#define kChatDBAlready          @"yz_chat_db_already"

@interface YZDBManager : NSObject

@property (nonatomic) int64_t lastVisibleTime;

+ (instancetype)sharedManage;

- (BOOL)createTableName:(NSString *)tableName;


/**
 插入

 @param data 消息体
 @param mediaType 消息类型
 @param sendTime 发送时间
 @param filePath 附件路径（比如视频的路径）
 @param fileKey 缩略图路径（比如视频的缩略图）
 @param tableName 表名
 @param isSender 是否发送者
 @param sendStatus 发送状态
 @param senderAvatar 发送者头像
 @param receiverAvatar 接收者头像
 @return 插入标识
 */
- (BOOL)insertData:(NSData *)data
         mediaType:(NSString *)mediaType
          sendTime:(NSUInteger)sendTime
          filePath:(NSString *)filePath
           fileKey:(NSString *)fileKey
          isSender:(NSInteger)isSender
            status:(NSInteger)sendStatus
             table:(NSString *)tableName
      senderAvatar:(NSString *)senderAvatar
    receiverAvatar:(NSString *)receiverAvatar;


/**
 插入ChatMessageListTable数据

 @param data 数据
 @param tableName ChatMessageListTable
 @return 插入结果
 */
- (BOOL)insertMessageListData:(id)data
                    tableName:(NSString *)tableName;


/**
 插入新朋友表数据

 @param data 数据
 @param tableName NewFriendTable
 @return 插入结果
 */
- (BOOL)insertNewFriendData:(id)data
                  tableName:(NSString *)tableName;


- (BOOL)deleteDataFromTable:(NSString *)tableName withCondition:(NSString *)conditionStr;

- (BOOL)updateData:(id)data table:(NSString *)table andCondition:(NSString *)conditionStr;

- (id)queryDataFromTable:(NSString *)tableName andCondition:(NSString *)conditionStr;

/**
 获取记录条数

 @param tableName 表名
 @return 记录条数
 */
- (NSUInteger)getDataCountFromTable:(NSString *)tableName;


@end
